using Moq;
using NUnit.Framework;
using OpenWaves.ImageTransformations;

namespace OpenWaves.UnitTests.ImageTransformations
{
    [TestFixture]
    public class CropTransformationTests
    {
        [Test]
        public void CenteralCropTransformation_survives_serialization_deserializtion_roundtrip()
        {
            var transformation = new CentralCropTransformation(100, 100);

            Assert.That(ImageTransformation.Parse(transformation.ToString()), Is.EqualTo(transformation));
        }

        [Test]
        public void Given_Image_is_smaller_CentralCropTransformation_does_nothing()
        {
            var transformation = new CentralCropTransformation(100, 100);
            var imageMock = new Mock<IImage>(MockBehavior.Strict);
            imageMock.Setup(i => i.Width).Returns(10);
            imageMock.Setup(i => i.Height).Returns(10);

            transformation.ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }

        [Test]
        public void Given_Image_is_larger_CentralCropTransformation_calls_Crop()
        {
            var transformation = new CentralCropTransformation(10, 10);
            var imageMock = new Mock<IImage>(MockBehavior.Strict);
            imageMock.Setup(i => i.Width).Returns(100);
            imageMock.Setup(i => i.Height).Returns(100);
            imageMock.Setup(i => i.Crop(45, 45, 10, 10)).Verifiable();

            transformation.ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }

        [Test]
        public void Given_Image_is_wider_CentralCropTransformation_calls_Crop()
        {
            var transformation = new CentralCropTransformation(10, 100);
            var imageMock = new Mock<IImage>(MockBehavior.Strict);
            imageMock.Setup(i => i.Width).Returns(100);
            imageMock.Setup(i => i.Height).Returns(10);
            imageMock.Setup(i => i.Crop(45, 0, 10, 10)).Verifiable();

            transformation.ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }

        [Test]
        public void Given_Image_is_heigher_CentralCropTransformation_calls_Crop()
        {
            var transformation = new CentralCropTransformation(100, 10);
            var imageMock = new Mock<IImage>(MockBehavior.Strict);
            imageMock.Setup(i => i.Width).Returns(10);
            imageMock.Setup(i => i.Height).Returns(100);
            imageMock.Setup(i => i.Crop(0, 45, 10, 10)).Verifiable();

            transformation.ApplyToImage(imageMock.Object);

            imageMock.Verify();
        }
    }
}